#include "Capsules.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "Box.h"
#include "Sprite.h"
#include "MainGame.h"
#include "GunWeapon.h"
Capsules::Capsules(Box* box, SPRITE_ID weapongun_id) : Object(box)
{
	_box = box;
	_initpos=box->_position;
	_weapongun_id= weapongun_id;
}
void Capsules::init()
{
	_sprite = RSManager::getInstance()->getSprite(CAPSULES);
	_hits=1;
	_isAlive=false;
	_obj= ObjEnemy_DYNAMID;
	AssignMove(_box);
}
void Capsules :: update()
{
	if(gl_camera->getLeftSide()>_initpos.x+_box->_size.x){
		_isAlive=true;
		moveSinY(8);
	}
	if(_hits<=0|| _box->_position.x>gl_camera->getRightSide()) {
		_isAlive=false;
	}
	if(_hits<=0){
		GunWeapon* gunWeapon=new GunWeapon
			(new Box(_box->_position,D3DXVECTOR2(48,30),D3DXVECTOR2(0.1f,0)),_weapongun_id);
		gunWeapon->init();
		gl_MainGame->addWorldObject(gunWeapon);
	}
}
void Capsules::render()
{
	if(_isAlive)
	_sprite->Render(_box->_position);
}
Box* Capsules::getCollisionBox()
{
	_colBox->_position=_box->_position;
	_colBox->_size=_box->_size;
	return _colBox;
}
Capsules::~Capsules()
{
}
